#!/bin/bash

LABEL=3
SEP[0]=10000000
SEP[1]=100000000
SEP[2]=1000000000

while read line
do
  name=$(echo "$line" | sed 's/"\$/"/g;s/\([0-9]\),\([0-9]\)/\1\2/g' | awk 'BEGIN { FS = "\",\"" } { print $16"-"$15 }')
  echo "$line" | awk 'BEGIN { FS = "\",\""; OFS = "\",\"" } { $15 = ""; print }'> "bymovie/$name"
done < movie-check

rm -rf bymovie/label*
i=0
while [ $i -lt $LABEL ]
do
  mkdir "bymovie/label$i"
  i=$(expr $i + 1)
done

for file in bymovie/tt*
do
  bo=$(echo "$file" | sed 's/^.*-//g')
  j=0
  while [ $j -lt $LABEL ]
  do
    if [ $bo -lt ${SEP[$j]} ]
    then
      mv "$file" "bymovie/label$j"
      break
    fi
    j=$(expr $j + 1)
  done
done
